<%@ page import="com.checkfree.isolutions.customer.persist.*" %>
<%@ page import="com.checkfree.isolutions.statement.*" %>
<%@ page import="com.checkfree.isolutions.statement.persist.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.utils.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.controller.*" %>
<%@ page import="com.checkfree.isolutions.property.Properties" %>
<%@ page import="com.checkfree.isolutions.property.PropertiesConfig" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.text.*" %>
<%@ page import="my.com.wsClient.*" %>
<%@ page import="my.com.maxis.dao.*" %>

<%
		
	String acc = request.getParameter("accid");
	String ref = request.getParameter("statid");
	//String usr = request.getParameter("username");
	String amount = request.getParameter("amt");
	String lflag = request.getParameter("lflag");
	System.out.println("1");
	if(lflag == null){
		out.println("<!doctype html>");
		out.println("<!-- HTML5 Boilerplate -->");
		out.println("<!--[if lt IE 7]><html class='no-js lt-ie9 lt-ie8 lt-ie7' lang='en'> <![endif]-->");
		out.println("<!--[if (IE 7)&!(IEMobile)]><html class='no-js lt-ie9 lt-ie8' lang='en'><![endif]-->");
		out.println("<!--[if (IE 8)&!(IEMobile)]><html class='no-js lt-ie9' lang='en'><![endif]-->");
		out.println("<!--[if gt IE 8]><html class='no-js' lang='en'><![endif]-->");
		out.println("<head>");
		out.println("<meta charset='utf-8'>");
		out.println("<title>Maxis Manage Bills</title>");
		out.println("<link rel='stylesheet' type='text/css' href='css/master.css' media='all'>");
		out.println("</head>");
		out.println("<script src='js/jquery-1.8.2.min.js'></script>");
		out.println("<script src='js/jquery-ui-1.9.2.custom.min.js'></script>");
		out.println("<script src='js/plugins.js'></script>");
		out.println("<script src='js/helper.js'></script>");
		out.println("<script src='js/jquery.easing.js'></script>");
		out.println("<script src='js/jquery.flexslider-min.js'></script>");
		out.println("<script src='js/jquery.fancybox.js'></script>");
		out.println("<script src='js/jquery.mousewheel.min.js'></script>");
		out.println("<script src='js/jquery.mCustomScrollbar.min.js'></script>");
		out.println("<script src='js/jquery.ui.datepicker.js'></script>");
		out.println("<script src='js/jquery-ui-timepicker-addon.js'></script>");
		if(session.getAttribute("totalAmountDue") == null){
			amount = "0";
		}else{
			amount = (String)session.getAttribute("totalAmountDue");
		}
	}
	System.out.println("2");
	String paypalURL = "PaypalCheckout";
	String masterVisaURL = "CusProcessPayment.jsp";
	String amt = amount;
	if (amt.indexOf(',')>=0){
		  amt = EbppxUtil.removeChar(amt,',');
      }
	if (amt.indexOf('R')>=0){
		  amt = EbppxUtil.removeChar(amt,'R');
    }
	if (amt.indexOf('M')>=0){
		  amt = EbppxUtil.removeChar(amt,'M');
    }
	System.out.println("3");
	String amtDue = "-";
	my.com.maxis.dao.AccBillOutputDao accBillDao = null; 
	accBillDao = (AccBillOutputDao) session.getAttribute("AccountBillingInfo");
	if(accBillDao != null){
		amtDue = accBillDao.getTotalAmtDue();
		if(amtDue == null){
			amtDue = "-";
		}
	}

%>

<%!
public String formatAmount(double dblVal) {
  String Amount = "0.00";
    try {
        NumberFormat nf = NumberFormat.getNumberInstance ();
        nf.setMinimumFractionDigits(2);
        nf.setMaximumFractionDigits(2);
        Amount = nf.format(dblVal);
    }catch (Exception e){
    }
  return  Amount;
}
%>
<body style="background-color:white">
<div class="confirm-payment-amount popup">
	<div class="title">Confirm Payment Amount</div>
	<div class="content">
		<form action="" method="post" id ="paymentForm" name ="paymentForm">
			<input type="hidden" name="accid" value="<%=acc%>">
			<input type="hidden" name="statid" value="<%=ref%>">
			<fieldset>
			<%System.out.println("4"); %>
				<p><label for="account_no">Account No</label><%=acc%></p>
				<p><label for="amount_due">Bill Amount</label>RM<%=amt%></p>
				<p><label for="amount_due">Amount Due</label><%if(amtDue.equals("-")){out.print(amtDue);}else{out.print("RM"+formatAmount(Double.parseDouble(amtDue)));}%></p>
				<p><label for="payment">Payment</label><input type="text" name="amt" <%if(amtDue.equals("-")){out.print("value='30'");}else if(amtDue.indexOf("-") >= 0){out.print("value='30'");}else{out.print("value='"+amtDue+"'");}%>" /></p>
				<p><label>Payment Type</label>
					<select name="paymentType" id = "paymentType" style="width:50%">
						<option value="">Select Payment Type</option>
						<option value="<%=masterVisaURL%>">Maxis Pay</option>
						<option value="<%=paypalURL%>">Paypal</option>
					</select>
				</p>
				<small><strong>Note</strong><br />
					Transactions allowed only in Malaysian Ringgit (RM). Please contact your issuing bank for any dispute or complaints related to this payment. Your payment details will be securely transmitted using SSL 128 bit encryption.</p>
				</small>
				<p class="align_center"><input type="button" value="Next" class="btn" id="nextButtonSubmit"/></p>
				<p class="align_center"><img src="images/online_account/icon_maxispay.png" alt="Maxis Pay"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/online_account/paypal.gif" alt="Maxis Paypal" /></p>
				<p class="align_center">
					<a href="http://new.maxis.com.my/content/maxis/en/personal/services/addons/payment-and-financial-services/maxis-pay.html" target="_blank">Find out more <i class="icon-chevron-right"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="http://new.maxis.com.my/content/maxis/en/personal/services/addons/payment-and-financial-services/maxis-paypal.html"target="_blank">Find out more <i class="icon-chevron-right"></i></a>
				</p>
				<!-- <a href="https://new.maxis.com.my/content/maxis/en/personal/services/addons/payment-and-financial-services/maxis-easy-pay.html" class="group1" target="_blank"></a> -->
			</fieldset>
		</form>
	</div>
</div>
</body>
<%System.out.println("5"); %>
<script type="text/javascript">
	$("#nextButtonSubmit").click( function (event) {
		$form = $("#paymentForm");

		if(checkData(document.paymentForm)){
			if($('#paymentType').val()){
				$.fancybox.close();

					$form.attr("target", "_blank");
					$form.attr("action", $('#paymentType').val());
					$form.submit();
			}
			else{
				alert("Please select payment type!!");
			}
		}
		
		return false;
	});
	
	function checkData(frm){
		if(!isNumber(frm.amt.value)){
			alert("Please enter a valid amount to make payment");
			frm.amt.focus();
			return false;
		}
		if(Decimals(frm.amt.value,'.')>2){
			alert("Please enter the amount up till 2 decimal point only");
			frm.amt.focus();
			return false;
		}
		if(frm.amt.value<30){
			alert("The minimum payment using Paypal is RM30, kindly adjust your payment");
			frm.amt.focus();
			return false;
		}
		return true;
	}

	function redirect(){
		alert("3");
		this.location.href="ReleaseNotes.jsp";
		alert("4");
	s}

	// use dec_sep for internationalization
	function Decimals(x, dec_sep){
		var tmp=new String();
		tmp=x;
		if (tmp.indexOf(dec_sep)>-1)
			return tmp.length-tmp.indexOf(dec_sep)-1;
		else
			return 0;
	}

	function isNumber(n) {
		return !isNaN(parseFloat(n)) && isFinite(n);
	}

</script>
